package com.qingcheng.consumer;

import com.alibaba.fastjson.JSON;
import com.qingcheng.util.SmsUtil;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessageListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;

import java.util.Map;

/**
 * Welcome to the most Amazing IntelliJ IIIDEA.
 * Creat0r: ^_^ fffantianxing ^_^
 * Date: 2019-07-15
 * Time: 21:16
 */
public class SmsMessageConsumer implements MessageListener {

    @Autowired
    private SmsUtil smsUtil;
    @Value("${param}")
    private String param;

    @Override
    public void onMessage(Message message) {

        //从rabbitMQ中获取验证码
        String string = new String(message.getBody());
        Map<String, String> map = JSON.parseObject(string, Map.class);
        String phone = map.get("phone");
        String code = map.get("code");
        System.out.println("电话号码：" + phone + " 验证码：" + code);

        //调用阿里云通信发送短信
        smsUtil.sendSms(phone, param.replace("[value]", code));
    }
}
